package com.panda.system.controller;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.core.page.TableDataInfo;
import com.panda.common.enums.BusinessType;
import com.panda.common.utils.poi.ExcelUtil;
import com.panda.system.domain.TPandaEvalutionTask;
import com.panda.system.service.ITPandaEvalutionTaskService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;
import java.util.List;

/**
 * 评价任务看板Controller
 * 
 * @author panda
 * @date 2021-02-28
 */
@RestController
@RequestMapping("/system/EvalutionTask")
public class TPandaEvalutionTaskController extends BaseController
{
    @Autowired
    private ITPandaEvalutionTaskService tPandaEvalutionTaskService;

    /**
     * 查询评价任务看板列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TPandaEvalutionTask tPandaEvalutionTask)
    {
        startPage();
        if(tPandaEvalutionTask !=null &&tPandaEvalutionTask.getEndTime() != null){
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(tPandaEvalutionTask.getEndTime());
            calendar.add(Calendar.DATE, 1);
            tPandaEvalutionTask.setEndTime(calendar.getTime());
        }
        List<TPandaEvalutionTask> list = tPandaEvalutionTaskService.selectTPandaEvalutionTaskList(tPandaEvalutionTask);
        return getDataTable(list);
    }

    /**
     * 导出评价任务看板列表
     */
    @Log(title = "评价任务看板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TPandaEvalutionTask tPandaEvalutionTask)
    {
        List<TPandaEvalutionTask> list = tPandaEvalutionTaskService.selectTPandaEvalutionTaskList(tPandaEvalutionTask);
        ExcelUtil<TPandaEvalutionTask> util = new ExcelUtil<TPandaEvalutionTask>(TPandaEvalutionTask.class);
        return util.exportExcel(list, "task");
    }

    /**
     * 获取评价任务看板详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tPandaEvalutionTaskService.selectTPandaEvalutionTaskById(id));
    }

    /**
     * 新增评价任务看板
     */
    @Log(title = "评价任务看板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPandaEvalutionTask tPandaEvalutionTask)
    {
        return toAjax(tPandaEvalutionTaskService.insertTPandaEvalutionTask(tPandaEvalutionTask));
    }

    /**
     * 修改评价任务看板
     */
    @Log(title = "评价任务看板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPandaEvalutionTask tPandaEvalutionTask)
    {
        return toAjax(tPandaEvalutionTaskService.updateTPandaEvalutionTask(tPandaEvalutionTask));
    }

    /**
     * 删除评价任务看板
     */
    @Log(title = "评价任务看板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPandaEvalutionTaskService.deleteTPandaEvalutionTaskByIds(ids));
    }

    /**
     * 修改评价任务状态
     */
    @Log(title = "评价任务看板", businessType = BusinessType.UPDATE)
    @PostMapping("/changeTaskStatus")
    public AjaxResult changeTaskStatus(@RequestBody TPandaEvalutionTask tPandaEvalutionTask)
    {
        return toAjax(tPandaEvalutionTaskService.updateTPandaEvalutionTask(tPandaEvalutionTask));
    }

    /**
     * 创建评价待办
     */
    @ApiOperation("创建追评待办")
    @Log(title = "任务信息", businessType = BusinessType.INSERT)
    @PostMapping("/createAfterEvaluationTodo")
    public AjaxResult createAfterEvaluationTodo(@RequestBody TPandaEvalutionTask tPandaEvalutionTask)
    {
        return tPandaEvalutionTaskService.createAfterEvaluationTodo(tPandaEvalutionTask);
    }
}
